<template>
  <a-modal v-model="visible"   :title="title"  @cancel='cancel' @ok='sure'>
    <a-form-model :model="item" :label-col="{span :4 }" :wrapper-col="{ span: 20 }">
      <a-form-model-item label="名称" required>
        <a-input v-model="item.name"  />
      </a-form-model-item>
      <a-form-model-item label="内容" >
        <a-input v-model="item.content" type="textarea" :auto-size="{ minRows: 5 ,maxRows: 5}"/>
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>

<script>
import ReportsEpidemicDailyService from '@/myService/ReportsEpidemicDailyService'

export default {
  name: 'CategoryEditModal',
  data(){
    return{
      visible:false,
      title:'',
      item:{},
      flag:false,
    }
  },
  methods:{
    open(title,item){
      this.title=title;
      if(item!==null){
        this.item=item;
        this.flag=true;
      }
      else {
        this.item={

        }
        this.flag=false;
      }
      this.visible=true
    },
    async cancel() {
      await this.$emit('updateCategory');
      this.visible = false;
    },
    sure(){
      if(this.item.name===''|| this.item.name===undefined){
        this.$message.error("名称不可为空")
        return;
      }
      if(this.flag){
        ReportsEpidemicDailyService.changeCategoryInfo(this.item).then(res=>{
          if(res.success){
            this.$message.success("更新成功")
            this.cancel()
          }else {
            this.$message.error(res.message)
          }
        })
      }else {
        ReportsEpidemicDailyService.addCategory(this.item).then(res=>{
          if(res.success){
            this.$message.success("更新成功")
            this.cancel()
          }else {
            this.$message.error(res.message)
          }
        })
      }

    }
  }
}
</script>

<style scoped>

</style>